<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends MY_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->page_auth->secure_welcome_page();
		$this->layout_view = 'application_no_side_bar';
		$this->load->library('token');
	}

	public function index()
	{
		$image = $this->_captcha();
		$this->token->destroy_token();
		$this->token->set_token();
		$this->session->set_userdata('word',$image->word);
		$this->view_data['captcha_image'] = $image->image;
		$this->view_data['form_token'] = $this->token->get_token();//generate form token;
	}
	
	public function login()
	{
		$this->layout_view = 'login_2';
		$image = $this->_captcha(226);
		$this->session->set_userdata('word',$image->word);
		$this->view_data['captcha_image'] = $image->image;
		$this->view_data['form_token'] = $this->token->get_token();//generate form token;
	}
	
	private function _captcha()
	{
		$this->load->helper('captcha');
		$system_counted_hash = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
		$vals = array(
			'word'	 => substr(md5(rand(1,100).$system_counted_hash),3,rand(2,5)),
			'img_path'	 => './captcha/',
			'img_url'	 => base_url().'auth/captcha',
			'font_path'	 => './assets/_fonts/4.ttf',
			'img_width'	 => '150',
			'img_height' => 35,
			'expiration' => 7200
			);
		
		$cap = create_captcha($vals);
		$image['word'] = $cap['word'];
		$image['image'] ='<image src="'.base_url().'captcha/'.$cap['time'].'.jpg"/>';
		$image['link'] = './captcha/'.$cap['time'].'.jpg';

		return (object)$image;
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */